[Fix] 내가 다녀온 산 목록 API에서 imageUrl null 반환 수정#159
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 본 PR은 사용자가 다녀온 산 목록을 조회하는 API에서 산 이미지 URL이 올바르게 표시되지 않던 버그를 수정합니다. 데이터베이스 스키마 변경 사항을 반영하여 잘못된 컬럼 참조를 수정함으로써 데이터 조회 기능을 정상화하는 것을 목적으로 합니다. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the HikingRecordRepository to extract the first image URL from a JSONB array (image_urls->>0) instead of using a single image_url column. The review feedback suggests optimizing the SQL query by grouping by the primary key m.id instead of repeating multiple columns in the GROUP BY clause, leveraging PostgreSQL's functional dependency to simplify the query and improve maintainability.
| SELECT | ||
| hr.mountain_id AS mountainId, | ||
| m.name AS mountainName, | ||
| m.image_url AS imageUrl, | ||
| m.image_urls->>0 AS imageUrl, | ||
| COUNT(hr.id) AS hikingCount, | ||
| MAX(hr.created_at) AS lastHikedAt | ||
| FROM hiking_records hr | ||
| JOIN hiking_members hm ON hm.hiking_record_id = hr.id | ||
| JOIN mountains m ON m.id = hr.mountain_id | ||
| WHERE hm.user_id = :userId | ||
| GROUP BY hr.mountain_id, m.name, m.image_url | ||
| GROUP BY hr.mountain_id, m.name, m.image_urls->>0 | ||
| ORDER BY MAX(hr.created_at) DESC, hr.mountain_id DESC |
There was a problem hiding this comment.
PostgreSQL에서는 GROUP BY 절에 테이블의 기본 키(Primary Key)인 m.id를 지정하면, 해당 테이블의 다른 컬럼들(m.name, m.image_urls->>0 등)은 함수적 종속성(Functional Dependency) 덕분에 GROUP BY 절에 개별적으로 나열하지 않고도 SELECT 절에서 자유롭게 조회할 수 있습니다.\n\n현재 쿼리에서는 m.image_urls->>0과 같은 복잡한 표현식이 SELECT와 GROUP BY 양쪽에 중복되어 작성되어 있어, 향후 이미지 조회 로직이 변경될 때 두 곳 모두 수정해야 하는 유지보수 상의 번거로움이 있습니다.\n\n따라서 SELECT 절에서 hr.mountain_id 대신 m.id를 조회하고, GROUP BY 절을 m.id로 단순화하면 쿼리의 가독성과 유지보수성을 크게 향상시킬 수 있습니다.
| SELECT | |
| hr.mountain_id AS mountainId, | |
| m.name AS mountainName, | |
| m.image_url AS imageUrl, | |
| m.image_urls->>0 AS imageUrl, | |
| COUNT(hr.id) AS hikingCount, | |
| MAX(hr.created_at) AS lastHikedAt | |
| FROM hiking_records hr | |
| JOIN hiking_members hm ON hm.hiking_record_id = hr.id | |
| JOIN mountains m ON m.id = hr.mountain_id | |
| WHERE hm.user_id = :userId | |
| GROUP BY hr.mountain_id, m.name, m.image_url | |
| GROUP BY hr.mountain_id, m.name, m.image_urls->>0 | |
| ORDER BY MAX(hr.created_at) DESC, hr.mountain_id DESC | |
| SELECT\n m.id AS mountainId,\n m.name AS mountainName,\n m.image_urls->>0 AS imageUrl,\n COUNT(hr.id) AS hikingCount,\n MAX(hr.created_at) AS lastHikedAt\n FROM hiking_records hr\n JOIN hiking_members hm ON hm.hiking_record_id = hr.id\n JOIN mountains m ON m.id = hr.mountain_id\n WHERE hm.user_id = :userId\n GROUP BY m.id\n ORDER BY MAX(hr.created_at) DESC, m.id DESC |
References
- 우선순위 가이드에 따라 유지보수성(Maintainability) 및 가독성(Readability)을 개선하기 위해 중복된 표현식을 제거하고 쿼리를 단순화합니다. (link)
🧾 요약
/api/hiking-records/me/mountains)에서imageUrl이 null로 내려오는 버그 수정 — 존재하지 않는image_url컬럼 대신image_urls->>0으로 변경🔗 이슈
✨ 변경 내용
HikingRecordRepository.findUserHikingMountainRecordsByUserId쿼리에서m.image_url→m.image_urls->>0으로 변경GROUP BY절도 동일하게 수정✅ 확인